﻿using System;
using System.IO;
using System.Text;
using System.Windows.Controls;

namespace Spremni_List
{
    public class TextBoxOutputter : TextWriter
    {
        RichTextBox textBox = null;

        public TextBoxOutputter(RichTextBox output)
        {
            textBox = output;
            
        }

        public override void Write(string value)
        {
            base.Write(value);
            textBox.Dispatcher.BeginInvoke(new Action(() =>
            {
                textBox.AppendText(value.ToString());
                textBox.ScrollToEnd();
            }));
        }

        public override Encoding Encoding
        {
            get { return System.Text.Encoding.ASCII; }
        }
    }

    public class TextBoxOutputterErr : TextWriter
    {
        RichTextBox textBox = null;

        public TextBoxOutputterErr(RichTextBox output)
        {
            textBox = output;
            textBox.IsDocumentEnabled = true;
        }

        public override void Write(string value)
        {
            base.Write(value);
            textBox.Dispatcher.BeginInvoke(new Action(() =>
            {
                Expander exp1 = new Expander();
                exp1.Content = value.ToString();
                textBox.IsDocumentEnabled = true;
                System.Windows.Documents.InlineUIContainer c = new System.Windows.Documents.InlineUIContainer(exp1, textBox.CaretPosition.DocumentEnd);
                textBox.AppendText(Environment.NewLine);
            }));
        }

        public override Encoding Encoding
        {
            get { return System.Text.Encoding.ASCII; }
        }
    }
}


